package com.hm.ibsm.auto.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hm.common.annotation.WebClientRequestIntercept;
import com.hm.common.util.CommonUtil;
import com.hm.common.util.EncryptUtil;
import com.hm.ibsm.auto.ManageProperties;
import com.hm.ibsm.util.R.RedisConfig;
import com.hm.ibsm.util.RedisUtilLock;

/**
 * @author shishun.wang
 * @date 2017年2月24日 下午6:00:45
 * @version 1.0
 * @describe
 */
@Component
public class WebClientRequestInterceptHandler {

	@Autowired
	private RedisUtilLock redisUtilLock;

	@Autowired
	private ManageProperties manageProperties;

	public void handler(WebClientRequestIntercept intercept, String token, String uri) {
		if (CommonUtil.isEmpty(intercept) || !intercept.frequency()) {
			return;
		}
		if (manageProperties.getRedisConfig().isOpenRequestLock()) {
			String key = new String(EncryptUtil.Base64.decode(token.toCharArray())) + "_" + Math.abs(uri.hashCode());
			redisUtilLock.new Client().checkTimeOutLock(RedisConfig.REQUEST_LOCK + key);
		}
	}
}
